import QtQuick 1.1
import com.nokia.meego 1.1

Page {

    property string name
    property string persons
    property string acnt_id
    property bool edit: false

    function close(save)
    {
        appWindow.pageStack.pop()
        if(save) {
            if(edit) {
                myData.editAccount(acnt_id, name_T.text, persons_T.text)
            }else {
                myData.addAccount(acnt_id, name_T.text, persons_T.text)
            }
        }
    }

    Column {
        id: edit_C
        width: parent.width
        spacing: 10
        anchors.leftMargin: 20
        anchors.topMargin: 20
        anchors.top: parent.top
        Rectangle {
            id: titleField
            height: 56
            width: parent.width
            anchors.topMargin: 20
            color: "#6400BC"
            Row {
                anchors.leftMargin: 20
                anchors.verticalCenter: titleField.verticalCenter
                height: parent.height
                Image {
                    id: supplement
                    source: "image://theme/icon-l-contacts"
                    height: titleLabel.height
                    width: 75
                    fillMode: Image.PreserveAspectFit
                    anchors.leftMargin: 5
                    anchors.rightMargin: 5
                    anchors.verticalCenter: parent.verticalCenter
                }
    
                Label {
                    id: titleLabel
                    anchors.verticalCenter: parent.verticalCenter
                    font.capitalization: Font.MixedCase
                    color: "white"
                    text: edit? "Edit Account" : "Add Account" 
                }
            }
    
            Image {
                id: closeButton
                anchors.verticalCenter: titleField.verticalCenter
                anchors.right: titleField.right
                anchors.rightMargin: 20
                height: titleLabel.height
                fillMode: Image.PreserveAspectFit
    
                source: "image://theme/icon-m-common-dialog-close"
                smooth: true
    
                MouseArea {
                    id: closeButtonArea
                    anchors.fill: parent
                    onClicked:  { close(false); }
                }
            }
        }
    
        Column {
            id: account
            height: 300
            width: parent.width
            Column {
                spacing:20
                anchors.left: parent.left
                anchors.leftMargin: 20
                width: parent.width
                Column {
                    spacing: 5
                    width: parent.width
                    Label {
                        color: "white"
                        text: "Account Name"
                        anchors.left: parent.left
                    }
                    TextField {
                        id: name_T
                        maximumLength: 80
                        width: parent.width*0.8
                        text: name 
                        placeholderText: "Name"
                        anchors.left: parent.left
                    }
                }
                Column {
                    spacing: 5
                    anchors.left: parent.left
                    Label {
                        anchors.topMargin: 20
                        color: "white"
                        text: "Default number of People"
                        anchors.left: parent.left
                    }
                    ButtonRow {
                        id:obj
                        width: 200
                        height: 25
                        exclusive: false
                        anchors.left: parent.left
                        Button { iconSource: "image://theme/icon-s-common-remove";onClicked: if(persons_T.text>0){persons_T.text-=1} }
                        Button { id: persons_T; enabled:false; text: persons }
                        Button { iconSource: "image://theme/icon-s-common-add";onClicked: persons_T.text = Number(persons_T.text)+1 }
                    }
                }
            }
        }
    
        ButtonRow {
            height:50
            platformStyle: ButtonStyle { }
            anchors {
                horizontalCenter: parent.horizontalCenter
                topMargin: 50
            }
            Button {id: b1; text: "OK"; onClicked: close(true)}
            Button {id: b2; text: "Cancel"; onClicked: close(false)}
        }
    }

}
